package lab03.test03;

import java.io.*;

public class Test {
    public static void main(String[] args) {

        /**
         * 在某目录下创建一个文本文件test.txt，
         * 通过字节输出流向文件中写入“Beijing欢迎你！”，
         * 通过字节输入流读出文件中的内容并显示；
         * 如果在已有文件中再追加“我的学号是：你自己的学号”如何实现？(未完成)
         */

        String path = "D:\\dev\\lab03\\test.txt";

        /*字节流写文件*/
        FileOutputStream fileOutputStream;
        FileInputStream fileInputStream;
        try {
            fileOutputStream = new FileOutputStream(path);
            fileInputStream = new FileInputStream(path);

            fileOutputStream.write(new String("Beijing欢迎你！").getBytes());

            int data = 1;
            while (data != -1){

                System.out.print((data = fileInputStream.read()));

            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


        try {

            RandomAccessFile randomAccessFile = new RandomAccessFile(path,"rw");

            randomAccessFile.write(new String("我的学号是：1606101052").getBytes());

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
